//
//  NSDictionary+PropertyCode.m
//  GMNHeaderFile
//
//  Created by 1 on 16/7/26.
//  Copyright © 2016年 gmn_dark. All rights reserved.
//

#import "NSDictionary+PropertyCode.h"

@implementation NSDictionary (PropertyCode)
- (void)propertyCode
{
    
    // 属性跟字典的key一一对应
    NSMutableString *codes = [NSMutableString string];
    // 遍历字典中所有key取出来
    [self enumerateKeysAndObjectsUsingBlock:^(id  _Nonnull key, id  _Nonnull obj, BOOL * _Nonnull stop) {
        // key:属性名
        
        NSString *code;
        if ([obj isKindOfClass:[NSString class]])
        {
            code = [NSString stringWithFormat:@"@property (nonatomic ,copy) NSString *%@;",key];
        }
        else if ([obj isKindOfClass:NSClassFromString(@"__NSCFBoolean")])
        {
            code = [NSString stringWithFormat:@"@property (nonatomic ,assign) BOOL %@;",key];
        }
        else if ([obj isKindOfClass:[NSNumber class]])
        {
            const char * pObjCType = [((NSNumber*)obj) objCType];
            if (strcmp(pObjCType, @encode(int))  == 0) {
                code = [NSString stringWithFormat:@"@property (nonatomic ,assign) int %@;",key];
            }
            else if (strcmp(pObjCType, @encode(float)) == 0) {
                code = [NSString stringWithFormat:@"@property (nonatomic ,assign) float %@;",key];
            }
            else if (strcmp(pObjCType, @encode(double))  == 0) {
                code = [NSString stringWithFormat:@"@property (nonatomic ,assign) double %@;",key];
            }
            else if (strcmp(pObjCType, @encode(BOOL)) == 0) {
                code = [NSString stringWithFormat:@"@property (nonatomic ,assign) BOOL %@;",key];
            }
            else
            {
                code = [NSString stringWithFormat:@"@property (nonatomic ,copy) NSNumber *%@;",key];
            }
        }
        else if ([obj isKindOfClass:[NSArray class]])
        {
            code = [NSString stringWithFormat:@"@property (nonatomic ,copy) NSArray *%@;",key];
        }
        else if ([obj isKindOfClass:[NSDictionary class]])
        {
            code = [NSString stringWithFormat:@"@property (nonatomic ,copy) NSDictionary *%@;",key];
        }
        else if ([obj isKindOfClass:[NSNull class]])
        {
            code = [NSString stringWithFormat:@"@property (nonatomic ,copy)  NSString *%@;",key];
            
        }
        
        [codes appendFormat:@"\n%@\n",code];
        
    }];
    
    DLog(@"%@",codes);
    
}


@end
